<?php

/**

 * 分红豆日志管理

 * * @网店运维 (c) 2015-2018 ShopWWI Inc. (http://www.shopwwi.com)

 * @license    http://www.shopwwi.c om

 * @link       交流群号：111731672

 * @since      网店运维提供技术支持 授权请购买shopnc授权

 */

defined('ByShopWWI') or exit('Access Invalid!');

class member_share_beanControl extends BaseMemberControl {

	public function __construct() {
            parent::__construct();

	}
      
	public function indexOp() {
             $this->share_beanlistOp();
             exit;
	}
	

	/**
	 * 分红豆变更日志
	 */
	public function share_beanlistOp() {

            $model_bean = Model('share_bean');
          
            $condition = array();
            $condition['br_memberid'] = $_SESSION['member_id'];
            $list = $model_bean ->getShareBeanRecordList($condition, 20, '*', 'br_id desc');
            $change_count=intval($this->member_info['member_share_bean']/200);
            $change_count=$change_count>0?$change_count:0;
             if(chksubmit())
             {
                  $count_stock_right=intval($_POST['stock_right']);
                  if(($count_stock_right>0)&&($count_stock_right<=$change_count))
                  {
                      $insertarr=array();
                      $insertarr['br_memberid']=$this->member_info['member_id'];
                      $insertarr['br_membername']=$this->member_info['member_name'];
                      $insertarr['br_bean']=-($count_stock_right*200);
                      $result=$model_bean->saveShareBeanRecord('lottery_draw',$insertarr);
                      if($result)
                      {
                          showDialog('兑换成功');
                      }
                      else
                      {
                          showDialog('兑换失败');
                      }
                  }
                  else
                  {
                       showDialog('兑换失败');
                  }
             }
            
            //信息输出
            self::profile_menu('log', 'loglist');
            Tpl::output('show_page', $model_bean -> showpage());
            Tpl::output('list', $list);
            Tpl::output('change_count', $change_count);
            Tpl::showpage('member_share_bean_list');

	}

	


	

	
	/**
	 * 用户中心右边，小导航
	 *
	 * @param string    $menu_type  导航类型
	 * @param string    $menu_key   当前导航的menu_key
	 * @return
	 */

	private function profile_menu($menu_type, $menu_key = '') {

		$menu_array = array( array('menu_key' => 'loglist', 'menu_name' => '分红豆余额', 'menu_url' => 'index.php?act=member_share_bean'));

		switch ($menu_type) {
			case 'log' :
			default :
				break;
		}

		Tpl::output('member_menu', $menu_array);
		Tpl::output('menu_key', $menu_key);

	}

}
